package spring_introduction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

//@Component("personBean")
public class Person {

    @Value("${person.detrov.surname}")
    private String surname;

    @Value("${person.detrov.age}")
    private int age;
//    @Autowired
//    @Qualifier("catBean")
    private Pet pet;

    /*
    @Autowired
    public Person(@Qualifier("catBean") Pet pet) {
        System.out.println(this.getClass().getSimpleName() + " bean is created from constructor with params - " + pet);
        this.pet = pet;
    } */

    @Autowired
    public Person(Pet pet) {
        System.out.println(this.getClass().getSimpleName() + " bean is created from constructor with params - " + pet);
        this.pet = pet;
    }

    public Person(){
        System.out.println(this.getClass().getSimpleName() + " bean is created from default constructor");
    }

    // pet -> Pet -> setPet === <property name="pet" ref="myPet"/>
    //@Autowired
//    @Qualifier("dogBean")
    public void setPet(Pet pet) {
        System.out.println("Person has new pet - " + pet);
        this.pet = pet;
    }

    public void setSurname(String surname) {
        System.out.println(this + " set surname");
        this.surname = surname;
    }

    public void setAge(int age) {
        System.out.println(this + " set age");
        this.age = age;
    }

    public String getSurname() {
        return surname;
    }

    public int getAge() {
        return age;
    }

    public void callYourPet(){
        System.out.println("Come to me " + pet.getClass().getSimpleName());
        pet.say();
    }
}
